package it.polimi.travelDream.ejb.servlet;

import it.polimi.travelDream.ejb.interfaces.GiftListMgrRemote;
import it.polimi.travelDream.ejb.interfaces.PersonalizedMgrRemote;
import it.polimi.travelDream.ejb.interfaces.TravelListMgrRemote;
import it.polimi.travelDream.entities.Modified_Package;
import it.polimi.travelDream.entities.TravelList;




import java.io.IOException;
import java.util.Map;
import java.lang.Object;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TravelServlet
 */
@WebServlet("/DelPPackageFromGiftList")
public class DelPPackageFromGiftList extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@EJB
	PersonalizedMgrRemote ppmgr;

	
	@EJB
	GiftListMgrRemote glmgr;
	
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DelPPackageFromGiftList() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// TODO Auto-generated method stub
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//if empty fields
		Map<String, String[]> mappa = request.getParameterMap();
		
		glmgr.removeFromGiftList(Integer.parseInt(mappa.get("idGiftList")[0]));
		ppmgr.delPersonalizedPackage(Integer.parseInt(mappa.get("idPersonalizedPackage")[0]));
		request.setAttribute("message", "Travel succesfully deleted from Gift List.");
		request.getRequestDispatcher("/UHome.jsp").forward(request, response); 
		
	}

}
